home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bossa.arc / BOSS_SUP.ARC / POPUP.C < prev    next >
C/C++ Source or Header  |  1990-03-12  |  7KB  |  191 lines

  1. /*
  2. ** POPUP - Popup Menu/Window Driver
  3. **
  4. ** Copyright (c) 1985-1988 Philip A. Mongelluzzo
  5. ** All rights reserved.
  6. */
  7.  
  8. #include "windows.h"                    /* window header */
  9.  
  10. #undef UARROW                          /* dont argue with windows.h */
  11. #undef DARROW      
  12. #undef LARROW      
  13. #undef RARROW      
  14. #undef BS          
  15. #undef DEL         
  16. #undef RET         
  17. #undef ESC         
  18.  
  19.  
  20. #define UARROW  0x48                    /* define key codes */
  21. #define DARROW  0x50
  22. #define LARROW  0x4b
  23. #define RARROW  0x4d
  24. #define BS      0x0e
  25. #define DEL     0x53
  26. #define RET     0x1c
  27. #define ESC     0x01
  28. #define SPACE   0x39
  29.  
  30. #define v_setrev(atrib) ((atrib&0x88) | ((atrib>>4)&0x07) | ((atrib<<4)&0x70) )
  31.  
  32. /*
  33. ** Popup structure templates
  34. */
  35.  
  36.   struct mitem {                        /* menu item template */
  37.     int r;                              /* row */
  38.     int c;                              /* col */
  39.     char *t;                            /* text */
  40.     int rv;                             /* return value */
  41.   };
  42.  
  43.   struct pmenu {                        /* popup menu structure */
  44.     WINDOWPTR wpsave;                   /* place to hold window id */
  45.     int winopn;                         /* leave window open flag */
  46.     int lndx;                           /* last index */
  47.     int fm;                             /* first menu item index */
  48.     int lm;                             /* last menu item index */
  49.     struct mitem scrn[25];              /* a bunch of menu items */
  50.   };
  51.  
  52. /*
  53. ** Prototypes 
  54. */
  55.  
  56. #if BORLAND | WATCOM | MSC
  57. int popup(int page,
  58.               int row,
  59.               int col,
  60.               int width,
  61.               int height,
  62.               int atrib,
  63.               int batrib,
  64.               struct pmenu *mx,
  65.               int cflag);
  66. WINDOWPTR qpopup(int page,
  67.               int row,
  68.               int col,
  69.               int width,
  70.               int height,
  71.               int atrib,
  72.               int batrib,
  73.               struct pmenu *mx);
  74. #endif
  75.  
  76. /*
  77. *********
  78. * popup *
  79. *********
  80. */
  81.  
  82. popup(page,row,col,width,height,atrib,batrib,mx,cflag)
  83. int page;                               /* video page */
  84. int row, col;                           /* window - upper row/col */
  85. int width, height;                      /* window - height & width */
  86. struct pmenu *mx;                       /* pointer to popup menu struct */
  87. int cflag;                              /* close on return strike flag */
  88. int atrib, batrib;                      /* attributes - window & border */
  89. {
  90.  
  91.  
  92. int i;                                  /* scratch integer */
  93. WINDOWPTR w;                            /* window pointer */
  94. unsigned int c;                         /* key scan code,,char */
  95. int j;                                  /* 1st char scan index */
  96. char ch;                                /* CHARACTER (!scan code) Entered */
  97.  
  98.  
  99.   if(mx->winopn) {                      /* window is still open */
  100.     goto d0;                            /* enter processing loop */
  101.   }
  102.   mx->lndx = -1;                        /* set index out of range */
  103.   w = wn_open(page, row, col, width, height, atrib, batrib);
  104.   wn_sync(w,FALSE);                     /* sync cursor */
  105.   mx->wpsave = w;                       /* save pointer */
  106.   if (w == NULL) return(99);            /* out of mem or just fubar */
  107.   mx->winopn = TRUE;                    /* say window is open */
  108.  
  109.   i = 0;                                /* init index */
  110.  
  111.   while(mx->scrn[i].r != 99) {          /* for as long as we have data */
  112.     wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  113.     i++;
  114.   }
  115.  
  116. d0:
  117.   w = mx->wpsave;                       /* restore pointer */
  118.   i = mx->lndx;                         /* BLINDLY assume that we're back */
  119.   if(i < mx->fm) i = mx->fm;            /* and reset if "i" is now out of */
  120.   if(i > mx->lm) i = mx->fm;            /* range - (dumb, but it works) */
  121.   while(TRUE) {                         /* till we exit */
  122.     wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, v_setrev(atrib));
  123.     c = v_getch();                      /* Fetch keyboard character */
  124.     ch = c & 0xFF;                      /* character */
  125.     c = c >> 8;                         /* scan code */
  126.     if(c == ESC) break;                 /* ESC (user wants out) */
  127.     if(c == RET) {                      /* so RETURN */
  128.       if(cflag) {                       /* close window on return strike ? */
  129.         wn_close(w);                    /* close the window */
  130.         mx->winopn = FALSE;             /* say window is closed */
  131.       }
  132.       mx->lndx = i;                     /* remember last indx */
  133.       return(mx->scrn[i].rv);           /* return with rv */
  134.     }
  135.     if(c == DARROW) c = SPACE;          /* Down arrow acts like Space */
  136.     if(c == RARROW) c = SPACE;          /* Right arrow does too */
  137.     if(c == LARROW) c = BS;             /* Left arrow acts like Back Space */
  138.     if(c == UARROW) c = BS;             /* Up arrow does too */
  139.     if(c == SPACE || c == DEL || c == BS) {
  140.       wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  141.       if(c == SPACE)                    /* foreward ?? */
  142.         i++;                            /* bump index */
  143.       else
  144.         i--;                            /* decrement */
  145.       if(i < mx->fm) i = mx->lm;        /* wrap on either */
  146.       if(i > mx->lm) i = mx->fm;        /* end */
  147.     }                                   /* endif */
  148.     ch = toupper(ch);                   /* lets see if we can use 1st char */
  149.     for (j=mx->fm; j<=mx->lm; j++) {
  150.       if (ch == *mx->scrn[j].t) {  
  151.         wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  152.         i=j;                           
  153.         break;
  154.       }
  155.     }                                   /* end 1st char scan */
  156.   }                                     /* end while */
  157.   wn_close(w);                          /* bye bye */
  158.   mx->winopn = FALSE;                   /* say window is closed */
  159.   return(99);                           /* nothing selected */
  160. }
  161.  
  162. #ifdef COMMENTS
  163. /*
  164. **********                              /* quick popup... */
  165. * qpopup *                              /* this is a hack of popup */
  166. **********                              /* but the code fragment */
  167. */                                      /* could be of value */
  168. #endif
  169.  
  170. WINDOWPTR qpopup(page,row,col,width,height,atrib,batrib,mx)
  171. int page;                               /* video page */
  172. int row, col;                           /* window - upper row/col */
  173. int width, height;                      /* window - height & width */
  174. int atrib, batrib;                      /* atributes - window & border */
  175. struct pmenu *mx;                       /* pointer to text struct */
  176. {
  177. int i;                                  /* scratch integer */
  178. WINDOWPTR w;                            /* window pointer */
  179.  
  180.   w = wn_open(page, row, col, width, height, atrib, batrib);
  181.  
  182.   i = 0;                                /* init index */
  183.   while(mx->scrn[i].r != 99) {          /* for as long as we have data */
  184.     wn_puts(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t);
  185.     i++;
  186.   }
  187.   return(w);
  188. }
  189.  
  190. /* End */
  191.